//
// Ishtar C++ Utility Library
//
// Task Facility - Thread Group Private Header
//

#ifndef __ISHTAR_TASK_THREAD_GROUP_IMPL_H
#define __ISHTAR_TASK_THREAD_GROUP_IMPL_H

#include <Ishtar/Ishtar.h>

#if defined( ISHTAR_COMPILER_HAS_PRAGMA_ONCE )
#pragma once
#endif

#include <Ishtar/Task/ThreadGroup.h>
#include <Ishtar/Task/WorkExecutorImpl.h>
#include <Ishtar/Thread/Mutex.h>


namespace Ishtar
{

namespace Task
{

///////////////////////////////////////////////////////////////////////////////
//
// Thread Group
//

class ThreadGroupImpl : public WorkExecutorImpl
{
public:

    ThreadGroupImpl( ThreadGroup& host );

    void Shutdown();

    void SubmitWork( const Work& w );
    void AddReadyWork( const WorkImplPtr& w );
    
    void AddThread( const std::string& name, const ExecuteFunction& execFunc, Uint interval );
    void AddLoopThread( const std::string& name, const WorkFunction& workFunc, Uint interval );
    void AddOnceThread( const std::string& name, const WorkFunction& workFunc );


private:

    void WorkWrapper( const WorkImplPtr& work );

    ThreadGroup& m_host;
    
    mutable Mutex m_mutex;
};


///////////////////////////////////////////////////////////////////////////////

} // namespace Task

} // namespace Ishtar

#endif // __ISHTAR_TASK_THREAD_GROUP_IMPL_H
